const mongoose = require('../db')


const UserSchema = new mongoose.Schema({
    phone: {
        type: String,
        required: true
    },
    password: {
        type: String,
        required: true
    },
    //短token
    assect_token: {
        type: String,

    },
    //长token
    refach_token: {
        type: String,

    },
    faceId: String,
})
const UserModel = mongoose.model('user1', UserSchema)

//发起定期检查表
const DingTableSchema = new mongoose.Schema({
    year: {
        type: String,
        required: true
    },
    object: {
        type: String,
        required: true
    },
    startTime: {
        type: String,
        required: true
    },
    endTime: {
        type: String,
        required: true
    },
    name: {
        type: String,
        required: true
    },
    contet: {
        type: String,
    },
    timer: {
        type: String,
        default: Date.now()
    },
    array: {
        type: Array,
        default: []
    },
    jianTime: {
        type: String,
        required: true
    }
})
const DingTableModel = mongoose.model('dingTable', DingTableSchema)
//下发检查通知单
const NoticeTableSchema = new mongoose.Schema({
    bian: String,
    name: String,
    content: String,
    timer: String,
    //签发单位
    unit: {
        type: String,
        default: '齐溪水库灌区管理中心'
    },
})

const NoticeTableModel = mongoose.model('noticeTable', NoticeTableSchema)



const RusultSchema = new mongoose.Schema({
    bian: String,
    name: String,
    content: String,
    timer: String,
    file: String,
    //签发单位
    unit: {
        type: String,
        default: '齐溪水库灌区管理中心'
    },
    rusult: String,//检查结果
})

const Rusult = mongoose.model('Rusult', RusultSchema)

//特别检查
const SpecialSchema = new mongoose.Schema({
    title: String,
    year: String,
    name: String,
    time: String,
    rusult: String,
})
const SpecialModel = mongoose.model('Special', SpecialSchema)

//日常维修
const DailySchema = new mongoose.Schema({
    name: String,  //工作名称
    yuan: String, //原因
    finish: String, // 计划完成事件
    state: {
        type: String,
        default: '待处理'
    },
    time: String, //完成时间
    zhiding: String, //指定人
    person: String, // 记录人
    file: Array,
})

const DailyModel = mongoose.model('Daily', DailySchema)

//维修结果
const RepairSchema = new mongoose.Schema({
    //和日常维修连接
    daily: {
        type: mongoose.Types.ObjectId,
        ref: 'Daily'
    },
    file: String, //完成照片
    rusult: String, // 维修结果
    time: String,  // 维修时间
    name: String, // 维修人
    shebei: String, // 维修设备
    buwei: String,  // 维修部位
    content: String,    // 维修内容
})
const RepairModel = mongoose.model('Repair', RepairSchema)

module.exports = { UserModel, DingTableModel, NoticeTableModel, Rusult, SpecialModel, DailyModel, RepairModel };